/*
 *
 * @ProjectName:    my_umi_app
 * @Package:
 * @ClassName:      share_url_api
 * @Description:    友情链接请求接口
 * @Author:         SuPeiSen
 * @CreateDate:     2021/2/23 11:57 上午
 * @UpdateDate:     2021/2/23 11:57 上午
 * @UpdateRemark:   更新说明：
 * @Version:        1.0
 */

import { Requests } from '@/utils/requests';
import { ApiPath } from '@/config/api_config';
import { ShareUrlItem, ShareUrlListType } from '@/type/share_url_type';
import { boolToNumOneOrZero } from '@/utils/app_fun';

/**
 * 添加友情链接
 * @param param
 * @constructor
 */
export const AddShareUrlApi = async (param: any) => {
  param.px = Number(param.px ?? 99);
  const model = await Requests.defaults.http('post', ApiPath.addShareUrl, {
    postData: param,
  });
  return model.success;
};

/**
 * 更新友情链接
 * @param id
 * @param param
 * @constructor
 */
export const UpdateShareUrlApi = async (id: number, param: any) => {
  param.id = id;
  const model = await Requests.defaults.http('put', ApiPath.updateShareUrl, {
    postData: param,
  });
  return model.success;
};

/**
 * 获取友情链接
 * @constructor
 */
export const GetShareUrlListApi = async (param: {
  page: number;
  limit: number;
}) => {
  const model = await Requests.defaults.http<ShareUrlListType>(
    'post',
    ApiPath.getShareUrlList,
    {
      postData: {
        page: param.page,
        limit: param.limit,
      },
    },
  );
  return model;
};

/**
 * 根据id更新状态
 * @param id
 * @param param
 * @constructor
 */
export const UpdateShareUrlStatusApi = async (param: {
  id: number;
  status: boolean;
}) => {
  const model = await Requests.defaults.http(
    'put',
    ApiPath.updateShareUrlStatus,
    {
      postData: {
        id: param.id,
        status: boolToNumOneOrZero(param.status),
      },
    },
  );
  return model.success;
};

/**
 * 根据id删除友情链接
 * @param id
 * @constructor
 */
export const DeleteShareUrlApi = async (id: number) => {
  const model = await Requests.defaults.http('delete', ApiPath.deleteShareUrl, {
    getData: {
      id: id,
    },
  });
  return model.success;
};

/**
 * 通过id获取友情链接
 * @param id
 * @constructor
 */
export const GetShareUlrByIdApi = async (id: number) => {
  return await Requests.defaults.http<ShareUrlItem>(
    'get',
    ApiPath.getShareUrlById,
    {
      getData: {
        id: id,
      },
    },
  );
};
